Component({
	options: {
		"styleIsolation": "apply-shared"
	},
	properties: {
		imageData: {
			type: Array,
			value: []
		}
	},
	data: {
		talentLeft: [],
		talentRight: []
	},
	methods: {
		// 封装获取图片高度信息
		getImageInfo(src) {
			return new Promise((resolve) => {
				wx.getImageInfo({
					src,
					complete(res) {
						resolve( { 
							height: res.height,
							width: res.width
						})
					},
				})
			})
		},
		
		//实现瀑布流
		async pinterest(imageData) {
			var width = 164, 
					talentList = imageData,
					picList = [],
					leftHeight = 0,
					rightHeight = 0,
					leftList = [],
					rightList = []
			for (let i = 0; i < talentList.length; i++) {
				picList.push(talentList[i].url)
			}
			let loadPicPs=[]
			let imgHeight = 0
			for(let i = 0; i < picList.length; i++){
				loadPicPs.push(await this.getImageInfo(picList[i]))
				imgHeight = width / loadPicPs[i].width * loadPicPs[i].height
					if( leftHeight <= rightHeight ){
						leftList.push(talentList[i])
						leftHeight = leftHeight + imgHeight
					} else {
						rightList.push(talentList[i])
						rightHeight = rightHeight + imgHeight
					}
					this.setData({
						talentLeft: leftList,
						talentRight: rightList
					});
			}
		},
	},
	ready(){
		this.pinterest(this.data.imageData)
	}
})